
import { _decorator } from 'cc';
import BasePanel from '../../../core/component/BasePanel';
import Data from '../../../core/manager/Data';
import WXTTUtils from '../../../core/manager/WXTTUtils';
import AudioMgr from '../../../core/utils/AudioMgr';
const { ccclass, property } = _decorator;

@ccclass('SettingLayer')
export class SettingLayer extends BasePanel {

    start()
    {
        WXTTUtils.showInterstitialAd();
        this.updateUI();
    }

    updateUI()
    {
        this.GetGameObject("sound-on-icon").active = Data.user.soundVolume != 0;
        this.GetGameObject("sound-off-icon").active = Data.user.soundVolume == 0;
        
        this.GetGameObject("vibration-on-icon").active = Data.user.vibration != 0;
        this.GetGameObject("vibration-off-icon").active = Data.user.vibration == 0;
    }

    onBtnClicked(event:any, customEventData:any) {
        AudioMgr.Instance().playSFX('btnclick')
        var btnName = event.target.name;
        switch (btnName) {
            case "btn_close":
                this.close();
                break;
            case "btn_sound":
                Data.user.soundVolume = Data.user.soundVolume == 0?1:0;
                this.updateUI();
                break;
            case "btn_vibration":
                Data.user.vibration = Data.user.vibration == 0?1:0;
                this.updateUI();
                break;
        }
    }
}
